/***
This do-file creates a figure showing the effect of the quartile threshold 
adjustment we perform in the employment pipeline. 
***/

*-------------------------------------------------------------------------------
* Set up
*-------------------------------------------------------------------------------

* Set $root
project figstabs, root
if (r(buildrunning)==0) include "${root}/code/config_interactive.do"

* Set globals
project, uses("${root}/code/set_globals.do")
include "${root}/code/set_globals.do"

* Create required subfolders
cap mkdir "${root}/results/Employment"

*-------------------------------------------------------------------------------
* Import paychex intermediate file
*-------------------------------------------------------------------------------
project, uses("${root}/data/dvc/Employment/Paychex intermediate file for quartile threshold adjustment figure.dta")
use "${root}/data/dvc/Employment/Paychex intermediate file for quartile threshold adjustment figure.dta", clear

* Keep relevant period
keep if inrange(date, mdy(8, 1, 2020), mdy(8, 1, 2021)) 

*-------------------------------------------------------------------------------
* Plot 
*-------------------------------------------------------------------------------

tw (line norm_employee date if quartile == 2 & inrange(date, mdy(1, 1, 2020), mdy(12, 31, 2021)), sort lcolor(oi2%50) lpattern(dash)) ///
   (line norm_employee date if quartile == 3 & inrange(date, mdy(1, 1, 2020), mdy(12, 31, 2021)), sort lcolor(oi1%50) lpattern(dash)) ///
   (line norm_employee_smooth date if quartile == 2 & inrange(date, mdy(1, 1, 2020), mdy(12, 31, 2021)), sort lcolor(oi2)) ///
   (line norm_employee_smooth date if quartile == 3 & inrange(date, mdy(1, 1, 2020), mdy(12, 31, 2021)), sort lcolor(oi1)) ///
   , ///
   ytitle("Change in Employment (%)" "Relative to January 2020") ///
   xtitle("") ///
   xline(`=mdy(3, 1, 2021)', lpattern(dash) lcolor(gs8)) ///
   text(28 `=mdy(3, 1, 2021) + 5' "Threshold separating Q2 and Q3" "crosses above $20/hour", placement(east) color(gs8) justification(left) size(3)) ///
   ylabel(-10 "-10%" 0 "0%" 10 "+10%" 20 "+20%" 30 "+30%", nogrid) ///
   xlab(`=mdy(8, 1, 2020)' `""Aug" "2020""' ///
	`=mdy(10, 1, 2020)' "Oct" ///
	`=mdy(12, 1, 2020)' "Dec" ///
	`=mdy(2, 1, 2021)' `""Feb" "2021""' ///
	`=mdy(4, 1, 2021)' "Apr" ///
	`=mdy(6, 1, 2021)' "Jun" ///
	`=mdy(8, 1, 2021)' `""Aug" "2021""' ///
	, format(%tdm) labsize(medsmall))  ///
	legend(order(1 "Q2 Before Adjustments" 2 "Q3 Before Adjustments" 3 "Q2 Adjusted" 4 "Q3 Adjusted") col(2) size(small))

oi_graph_export "${root}/results/Employment/Before and After Quartile Threshold Adjustment - Q2 and Q3", type(${fig_type}) 
